<%--
  Created by IntelliJ IDEA.
  User: limin
  Date: 2021/8/9
  Time: 21:08
  To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" import="java.util.*" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ page import="com.beans.AdminInfo" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<!DOCTYPE HTML>
<html>
<head>
    <base href="<%=basePath%>">

    <title></title>

    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">

    <link rel="stylesheet" type="text/css" href="css/edittable.css"  >
    <link rel="stylesheet" type="text/css" href="css/validate.css"  >
    <script type="text/javascript"  src="js/jquery-1.8.0.js"></script>
    <script>
        $(function(){
            $("input[type=text],textarea").focus(function(){
                $(this).addClass("input_focus");
            }).blur(function(){
                $(this).removeClass("input_focus");
            });

            $(".form_btn").hover(function(){
                    $(this).css("color","red").css("background","#6FB2DB");
                },

                function(){
                    $(this).css("color","#295568").css("background","#BAD9E3");
                });
        });
    </script>
    <script>
        $(function (){
            $("#oldpassword").blur(function (){
                checkOldPassword();
            })
        })

        function checkOldPassword(){
            $.ajax({
                type:"post",
                url:"AdminServlet.do",
                data:{
                    id:$("#id").val(),
                    oldpassword:$("#oldpassword").val(),
                    flag:"checkOldPassword"
                },
                success:function (data){
                    if (data == 1){
                        $("#oldpassword_msg").html("旧密码输入正确")
                        return true;
                    }else {
                        $("#oldpassword_msg").html("旧密码输入错误")
                        return false;
                    }
                }
            })
        }

        function checkNewPassword(){
            var reg = /^[a-zA-Z0-9]{6,20}$/
            if( reg.test( $("#newpassword").val() ) ){
                $("#newpassword_msg").html("密码可用")
                return true;
            }
            $("#newpassword_msg").html("密码格式错误")
            return false;
        }

        function checkNewPWDConfirm(){
            if(document.getElementById("newpassword").value == $("#newpwdconfirm").val()){
                $("#newpwdconfirm_msg").html("密码可用")
                return true;
            }
            $("#newpwdconfirm_msg").html("两次密码不一致")
            return false;
        }

        function check(){
            var result = true;
            if(checkNewPassword()==false){
                result = false;
            }
            if(checkNewPWDConfirm()==false){
                result = false;
            }
            if (checkOldPassword()==false){
                result = false;
            }
            if(result == true){
                return confirm("确认提交吗");
            }
            return result;
        }
    </script>
</head>
<%
    AdminInfo admin = (AdminInfo) request.getSession().getAttribute("session_admin");
    request.setAttribute("admin",admin);
%>
<body>
<div class ="div_title">
    <div class="div_titlename"> <img src="images/san_jiao.gif" ><span>修改密码</span></div>
</div>

<form action="AdminServlet.do?flag=updateAdminPassword" method="post"  onsubmit="return check()">
    <table class="edit_table" >
        <tr>
            <td class="td_info">用户账号:</td>
            <td class="td_input_short">
                <input type="hidden" name="id" id="id" value="${admin.id}">
                <label>
                    ${admin.adminName}
                </label>
            </td>
            <td>
                <label class="validate_info" id="adminName_msg"></label>
            </td>
        </tr>
        <tr>
            <td class="td_info">请输入旧密码:</td>
            <td>
                <input type="password"  class="txtbox"  name="oldpassword"  id="oldpassword" value="">
            </td>
            <td><label  class="validate_info" id="oldpassword_msg" ></label></td>
        </tr>
        <tr>
            <td class="td_info">新密码:</td>
            <td>
                <input type="password"  class="txtbox"  name="newpassword"  id="newpassword" value="">
            </td>
            <td><label  class="validate_info" id="newpassword_msg" >数字或英文,6-20位</label></td>
        </tr>
        <tr>
            <td class="td_info">重复密码:</td>
            <td><input type="password" class="txtbox" id="newpwdconfirm"  />
            </td>
            <td><label  class="validate_info"  id="newpwdconfirm_msg">请重复输入密码</label></td>
        </tr>

        <tr>
            <td class="td_info"> </td>
            <td>
                <input class="form_btn" type="submit" value="提交" />
                <button class="form_btn" onclick="window.history.back()" >返回 </button>
            </td>
            <td>
                <label id="result_msg" class="result_msg"></label>
            </td>
        </tr>
    </table>
</form>
</body>
${msg}
</html>
